package com.shanghaiyimu.yimiyangche.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.bean.CarBean;

import java.util.List;

/**
 * Author:ShangHaiYiMu
 * Time:2017/7/22   16:02
 * Description:ErshoucheAdapter
 */

public class ErshoucheAdapter extends BaseAdapter {

    private List<CarBean> datas;
    private Context context;

    public ErshoucheAdapter(List<CarBean> datas, Context context) {
        this.datas = datas;
        this.context = context;
    }

    @Override
    public int getCount() {
        return datas!= null?datas.size():0;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.ershoucar_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        CarBean carBean = datas.get(position);
        holder.name.setText(carBean.getName());
        holder.price.setText(carBean.getPrice());
        holder.xiaoliang.setText(carBean.getXiaoliang()+"");
//        int j = position+1;
        holder.pailei.setText(position+1+"");

        return convertView;
    }
    static class ViewHolder{
        private TextView name,price,xiaoliang,pailei;

        public ViewHolder(View view) {
            name = (TextView) view.findViewById(R.id.tehui_name);
            price = (TextView) view.findViewById(R.id.tehui_price);
            xiaoliang = (TextView) view.findViewById(R.id.tehui_xiaoliang);
            pailei = (TextView) view.findViewById(R.id.ershouche_item_txt1);
        }
    }
}
